/**
 * 华为云IoT设备相关类型定义
 */

// 认证请求
export interface AuthRequest {
  auth: {
    identity: {
      methods: string[];
      password: {
        user: {
          name: string;
          password: string;
          domain: {
            name: string;
          };
        };
      };
    };
    scope: {
      project: {
        name: string;
      };
    };
  };
}

// Token响应
export interface TokenResponse {
  token: {
    expires_at: string;
    methods: string[];
    catalog: ServiceCatalog[];
    roles: Role[];
    project: ProjectInfo;
    issued_at: string;
    user: UserInfo;
  };
}

interface ServiceCatalog {
  endpoints: Endpoint[];
  id: string;
  name: string;
  type: string;
}

interface Endpoint {
  id: string;
  interface: string;
  region: string;
  region_id: string;
  url: string;
}

interface Role {
  id: string;
  name: string;
}

interface ProjectInfo {
  domain: DomainInfo;
  id: string;
  name: string;
}

interface UserInfo {
  domain: DomainInfo;
  id: string;
  name: string;
  password_expires_at: string;
}

interface DomainInfo {
  id: string;
  name: string;
}

// 设备列表响应
export interface DeviceListResponse {
  devices: Device[];
  page: {
    count: number;
    marker: string;
  };
}

export interface Device {
  device_id: string;
  node_id: string;
  device_name: string;
  product_id: string;
  status: string;
  create_time: string;
  tags: Tag[];
  description?: string;
}

interface Tag {
  tag_key: string;
  tag_value: string;
}

// 设备影子响应
export interface DeviceShadowResponse {
  device_id: string;
  shadow: Shadow[];
}

export interface Shadow {
  service_id: string;
  desired: {
    properties: Record<string, any>;
    event_time: string;
  };
  reported: {
    properties: Record<string, any>;
    event_time: string;
  };
  version: number;
}

// 设备消息请求
export interface DeviceMessageRequest {
  message_id?: string;
  name: string;
  message: Record<string, any>;
  encoding: string;
  payload_format: string;
  topic?: string;
}

// 设备消息响应
export interface DeviceMessageResponse {
  message_id: string;
  result: {
    status: string;
    created_time: string;
    finished_time?: string;
  };
}

// 设备消息错误响应
export interface DeviceMessageErrorResponse {
  error_code: string;
  error_msg: string;
}
